<?php

namespace common\modules\wechat\models\backend;

use common\widgets\ActiveForm;
use common\widgets\Form;
use Yii;

/**
 * 模块编辑表单
 *
 * @package common\modules\wechat\models\backend
 */
class ModuleForm extends Module
{

    /**
     * @inheritdoc
     */
    public $isNewRecord;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return parent::rules();
    }

    const SCENARIO_CREATE = 'admin-create';
    const SCENARIO_UPDATE = 'admin-update';

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        return [
            'admin-create' => ['id',
                'name',
                'type',
                'category',
                'version',
                'ability',
                'description',
                'author',
                'site',
                'admin',
                'migration',
                'reply_rule',
                'created_at',
                'updated_at',
                'created_by',
                'updated_by',
            ],
            'admin-update' => ['id',
                'name',
                'type',
                'category',
                'version',
                'ability',
                'description',
                'author',
                'site',
                'admin',
                'migration',
                'reply_rule',
                'created_at',
                'updated_at',
                'created_by',
                'updated_by',
            ],
        ];
    }

    /**
     * 返回当前表单的名称
     *
     * @return string
     */
    public function classLabelName()
    {
        return Yii::t('backend/wechat', 'Module');
    }

    /**
     * 列表定义
     *
     * @param ActiveForm|Form $form
     * @param static          $model
     * @param mixed           $extra
     * @return array
     * @throws \yii\web\ServerErrorHttpException
     */
    public function formRows(&$form, $model, $extra)
    {
        return [
            [
                'columns'    => 3,
                'attributes' => [

                    'id' => [
                        'type'    => Form::INPUT_TEXT,
                        'options' => ['disabled' => true],
                    ],

                    'name' => [
                        'type' => Form::INPUT_TEXT,
                    ],

                    'author' => [
                        'type' => Form::INPUT_TEXT,
                    ],

                    'type' => [
                        'type'        => Form::INPUT_WIDGET,
                        'widgetClass' => Form::SELECT2_WIDGET_CLASS,
                        'options'     => [
                            'data' => self::$types,
                        ],
                    ],

                    'category' => [
                        'type'        => Form::INPUT_WIDGET,
                        'widgetClass' => Form::SELECT2_WIDGET_CLASS,
                        'options'     => [
                            'data' => $this->categoryArray(),
                        ],
                    ],

                    'version' => [
                        'type' => Form::INPUT_TEXT,
                    ],

                    'admin' => [
                        'type'        => Form::INPUT_WIDGET,
                        'widgetClass' => Form::SELECT2_WIDGET_CLASS,
                        'options'     => [
                            'data' => [
                                0 => '否',
                                1 => '是',
                            ],
                        ],
                    ],

                    'migration' => [
                        'type'        => Form::INPUT_WIDGET,
                        'widgetClass' => Form::SELECT2_WIDGET_CLASS,
                        'options'     => [
                            'data' => [
                                0 => '否',
                                1 => '是',
                            ],
                        ],
                    ],

                    'reply_rule' => [
                        'type'        => Form::INPUT_WIDGET,
                        'widgetClass' => Form::SELECT2_WIDGET_CLASS,
                        'options'     => [
                            'data' => [
                                0 => '否',
                                1 => '是',
                            ],
                        ],
                    ],
                ],
            ],

            [
                'columns'    => 1,
                'attributes' => [
                    'ability'    => [
                        'type' => Form::INPUT_TEXTAREA,
                    ],

                    'description' => [
                        'type' => Form::INPUT_TEXTAREA,
                    ],
                ],
            ],

            [
                'columns'    => 4,
                'attributes' => [

                    'created_at' => [
                        'type' => Form::INPUT_TEXT,
                    ],

                    'updated_at' => [
                        'type' => Form::INPUT_TEXT,
                    ],

                    'created_by' => [
                        'type' => Form::INPUT_TEXT,
                    ],

                    'updated_by' => [
                        'type' => Form::INPUT_TEXT,
                    ],

                ],
            ],
        ];
    }

}
